<template>
<div class="page_l">
  <div class="top_bg">
    <span class="span1 pos_a"></span>
    <span class="span2 pos_a"></span>
    <span class="span3 pos_a"></span>
    <span class="span4 pos_a"></span>
    <span class="span5 pos_a"></span>
    <span class="span6 pos_a"></span>
    <span class="span7 pos_a"></span>
    <span class="span8 pos_a"></span>
    <div class="main_div">
      
      <!-- <img class="logo_img" src="~@/assets/logo.png" alt=""> -->
      <img class="logo_img" src="https://bigdataapi.parkic.com/images/shuozhou.png" alt="">
      <div class="login_div">
        <div class="input_div">
          <img src="~@/assets/mobile.png" alt="">
          <input type="text" v-model="loginData.mobile" ref="inp1" placeholder="请输入手机号">
        </div>
        <div class="input_div">
          <img src="~@/assets/pwd.png" alt="">
          <input type="password" v-model="loginData.password" ref="inp2" placeholder="请输入密码">
        </div>
        <div class="input_div" v-show="roleList.length>1">
          <Select  v-model="loginData.id" placeholder="请选择平台" @on-change='changeR'>
            <Option v-for="(item,index) in roleList" :value="item.id" :key="index">{{ item.role_name }}</Option>
          </Select>
        </div>
        <!-- <Input size="large" type="text" >
          <i class="icon-youxiang iconfont iconfont1" slot="prepend"></i>
        </Input><br> -->
        <!-- <Input size="large" type="password" v-model="loginData.password" placeholder="请输入密码" @keyup.enter.native="loginTo">
          <i class="icon-mima iconfont" slot="prepend"></i>
        </Input> -->
        <Checkbox class="jzmm" v-model="isjz">记住密码</Checkbox>
      </div>
      <div class="login_btn btn" @click="loginTo">登 录</div>
    </div>
  </div>
  <div class="phone" @click="toPhone">400-962-5108</div>
</div>
</template>
<script>
import {login,role} from '@/api/api.js'
export default {
  data(){
    return{
      loginData:{
        mobile:'',
        password:'',
        login_type:1,
        id:''
      },
      password:'',
      roleList:[],
      isjz:true
    }
  },
  mounted(){
    const originalHeight=document.documentElement.clientHeight ||document.body.clientHeight;
    window.onresize = ()=>{
      return(()=>{
          //键盘弹起与隐藏都会引起窗口的高度发生变化
          const resizeHeight=document.documentElement.clientHeight || document.body.clientHeight;
          console.log("进入到判断页面高度=========");
          console.log("页面初始高度========="+originalHeight);
          console.log("软键盘弹起高度========="+resizeHeight);
          if(resizeHeight-0<originalHeight-0){
          //当软键盘弹起，在此处操作
          console.log("进入到软键盘弹起=========");
              document.querySelector('body').setAttribute('style', 'height:'+originalHeight+'px;');
              this.scrollerHeight=resizeHeight;
          }else{
          //当软键盘收起，在此处操作
          console.log("进入到软键盘收起=========");
          document.querySelector('body').setAttribute('style', 'height:100%;');
          this.scrollerHeight="100%";
          }
      })()
    }
  },
  created(){
    localStorage.token = ''
    this.loginData.mobile = localStorage.mobile
    this.loginData.password = localStorage.password
  },
  watch:{
    'loginData.mobile':function(val){
      if(val.length==11){
        this.getRole()
      }else{
        this.roleList = []
        this.loginData.id = ''
      }
    }
  },
  beforeDestroy(){
   
  },
  methods:{
    changeR(val){
      this.loginData.id = val
      this.item = this.roleList.find(item=>item.id==val)
    },
    getRole(){
      // if(this.loginData.mobile.length!=11){
      //   this.roleList = []
      //   this.loginData.id = ''
      //   return
      // }
      role.GetRoleList({mobile:this.loginData.mobile,pagesize:50,status:1}).then(res=>{
        this.roleList = res.data.data.reverse()
        this.changeR(res.data.data[0].id)
      })
    },
    loginTo(){
      let data = Object.assign({},this.loginData)
      data.password = this.$md5(this.loginData.password)
      login(data).then(res=>{
        if(res.status==1){
          localStorage.clear()
          if(this.isjz){
            localStorage.password = this.loginData.password
          }
          localStorage.myCity_name = this.item.CityInfo.abbreviation
          localStorage.myCity_type = this.item.CityInfo.type
          localStorage.myCity_id = this.item.CityInfo.id
          console.log(this.item)
          localStorage.mobile = this.loginData.mobile
          localStorage.IndexId = this.loginData.id
          localStorage.token=res.data.token 
          localStorage.nickname=res.data.nickname 
          this.$Message.success('登录成功')
          this.loginData.mobile=''
          this.loginData.password=''
          this.loginData.id=''

          this.$nextTick(()=>{
            this.$router.push('home')
          })
        }else{
          this.$Message.error(res.msg)
        }
      }).catch(err=>{
        this.$Message.error(err)
      })
    },
    toPhone(){
      window.location.href='tel:4009625108'
    }
  }
}
</script>
<style lang="scss" scoped>
.phone{
  width: 100%;
  text-align: center;
  position: absolute;
  bottom: 30px;
  font-size: 16px;
  color: #fff;
  font-weight: 600;
}
.page_l{
  width: 100%;
  height: 100%;
  position: relative;
}
.top_bg{
  width: 100%;
  height: 100%;
  position: relative;
  background: url(~@/assets/login_bg.png) no-repeat;
  background-size: 100% 100%;
  .span1{
    left: -4%;
    bottom: auto;
    background: hsla(0,0%,100%,.1);
  }
  .span2{
    right: 4%;
    top: 10%;
    background: hsla(0,0%,100%,.1);
  }
  .span3{
    top: 280px;
    right: 5.66666%;
    background: hsla(0,0%,100%,.3);
  }
  .span4{
    right: 7%;
    top: 320px;
    background: hsla(0,0%,100%,.15);
  }
  .span5{
      top: 38%;
      left: 1%;
      right: auto;
      background: hsla(0,0%,100%,.05);
  }
  .span6{
      width: 200px;
      height: 200px;
      top: 44%;
      left: 10%;
      right: auto;
      background: hsla(0,0%,100%,.15);
  }
  .span7{
      bottom: 50%;
      right: 36%;
      background: hsla(0,0%,100%,.04);
  }
  .span8{
        bottom: 70px;
      right: 2%;
      background: hsla(0,0%,100%,.2);
  }
}
.yy_div{
  position: absolute;
  display: flex;
  right: 20px;
  top: 20px;
  .yyimg{
    margin-left: 10px;
    width: 40px;
    cursor: pointer;
    padding: 5px;
  }
  .active{
    background: #5e72e4;
  }
}
.pos_a{
  position: absolute;
  height: 120px;
  width: 120px;
  border-radius: 50%;
}
.main_div{
  position: absolute;
  top: 45%;
  left: 50%;
  width: calc(100% - 50px);
  transform: translate(-50%,-50%);
  .logo_img{
    width: 80%;
    margin-left: 10%;
    margin-bottom: 30px;
  }
  .login_btn{
    margin-top: 40px;
    width: 100%;
  }
}
.login_div{
  box-shadow: 0 0px 30px 0px rgba(50, 50, 233, 0.5);
  padding: 40px 20px;
  background-color: rgba($color: #fff, $alpha: 0);
  border: .0625rem solid rgba(0,0,0,.05);
  border-radius: 16px;
  width: 100%;
  position: relative;
  .jzmm{
    position: absolute;
    right: 20px;
    bottom: 20px;
    color: #fff;
  }
  &::v-deep .ivu-input-group-append{
    padding: 0;
  }
  &::v-deep .ivu-select-selection{
    background: rgba($color: #000000, $alpha: .05);
    border: 1px solid rgba($color: #fff, $alpha: .5);
    color: #fff;
  }
  .input_div{
    position: relative;
    margin: 20px 0;
    input{
      height: 42px;
      border-radius: 6px;
      padding-left: 40px;
      width: 100%;
      background: rgba($color: #000, $alpha: 0.05);
      border: 1px solid rgba($color: #fff, $alpha: .5);
      font-size: 15px;
      color: #fff;
    }
    img{
      position: absolute;
      left: 14px;
      height: 16px;
      top: 12px;
    }
    input::-webkit-input-placeholder { /* WebKit browsers */ 
    color: #fff; 
    }
    input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */ 
    color: #fff; 
    }
    input::-moz-placeholder { /* Mozilla Firefox 19+ */ 
    color: #fff; 
    }
    input:-ms-input-placeholder { /* Internet Explorer 10+ */ 
    color: #fff; 
    }
  }
}
.rb_div{
  position:absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #5e72e4;
  cursor: pointer;
}
.btn{
    height: 48px;
    line-height: 48px;
    border-radius: 20px;
    color: rgb(46, 187, 226);
    background-color: rgba(193, 251, 255, 0.8);
    border-color: #5e72e4;
    box-shadow: -2px 3px 5px rgb(255 255 255 / 60%) inset, 2px -3px 5px rgb(0 0 0 / 20%) inset;
    font-weight: 600;
    text-align: center;
    border: 1px solid transparent;
    position: relative;
    text-transform: uppercase;
    -webkit-transition: all .15s ease;
    transition: all .15s ease;
    will-change: transform;
    letter-spacing: .025em;
    font-size: 18px;
    cursor: pointer;
}
.logo{
  position: absolute;
  left: 20px;
  top: 20px;
  height: 60px;
  z-index: 60;
}
.v_img{
  height: 40px;
  cursor: pointer;
}
</style>